#include <Wire.h>

#define LED 25
#define KEY 0

int freq1 = 2000;    // 频率
int channel1 = 0;    // 通道0，共16个通道，0~15
int resolution1 = 10;   // 分辨率，取值0~20，duty最大取值为2^resolution-1

void setup()
{
  ledcSetup(channel1, freq1, resolution1); // 设置通道0
  ledcAttachPin(LED, channel1);  // 将通道0与引脚19连接
  pinMode(KEY,INPUT);
}

void loop()
{
  if(!digitalRead(KEY))
    ledcWrite(channel1, 900);  // 输出PWM
  else
    ledcWrite(channel1, 0);  // 输出PWM
}